package tmt.usercenter.web;

import com.tmt.jpa.jpaservice.impl.TmtBaseRepoImpl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import tmt.usercenter.web.service.TableDataInitialService;

import javax.net.ssl.HttpsURLConnection;

@EnableJpaRepositories(basePackages = {"tmt.usercenter.web.repository"},
        repositoryBaseClass = TmtBaseRepoImpl.class)
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
//@EnableCaching
@EnableAsync
public class Application implements ApplicationListener<ApplicationReadyEvent> {

    public static String SYSTEM_ID = "app.tmt.usercenter";

    private static final Logger logger = LoggerFactory.getLogger(Application.class);

    @Autowired
    private TableDataInitialService initialService;

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        logger.debug("应用已启动！");
    }

    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        initialService.initialTables();
        logger.debug("----数据库默认数据初始化完毕----");

        //ssl连接允许域名为：localhost
        //ssl连接允许域名为：localhost
        HttpsURLConnection.setDefaultHostnameVerifier(
                (hostname, httpSession) -> hostname.equals("localhost") || hostname.endsWith(".lingling9.com"));
    }
}
